using System;
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;
using System.Data;

namespace IP.Core.IPBusinessService
{
	/// <summary>
	/// Summary description for DBStoredProc.
	/// </summary>
	public class DBStoredProc
	{
	#region members
		private bool m_command_executed  = false;
		private OracleCommand m_oracle_command = new OracleCommand();
	#endregion

		#region public interface
		public DBStoredProc(string i_strProcName)
		{
			//
			// TODO: Add constructor logic here
			//
			m_oracle_command.CommandText = i_strProcName;
			m_oracle_command.CommandType = CommandType.StoredProcedure;
		}

		public OracleParameter addDecimalInputParam(string ip_name , 
													decimal ip_value ){
		   return m_oracle_command.Parameters.Add(DBParamUtil.getDecimalInputParam(ip_name, ip_value));
		}
		public OracleParameter addDecimalOutputParam(string ip_name , decimal ip_value ){
			return m_oracle_command.Parameters.Add(DBParamUtil.getDecimalOutputParam(ip_name, ip_value));
		}
		public OracleParameter addVarcharInputParam(string ip_name , string ip_value ){
			return m_oracle_command.Parameters.Add(DBParamUtil.getVarcharInputParam(ip_name, ip_value));
		}
		public OracleParameter addVarcharOutputParam(string ip_name , string ip_value ){
			return m_oracle_command.Parameters.Add(DBParamUtil.getVarcharOutputParam(ip_name, ip_value));
		}
		public OracleParameter addDateInputParam(string ip_name , DateTime ip_value ){
			return m_oracle_command.Parameters.Add(DBParamUtil.getDateInputParam(ip_name, ip_value));
		}
		public OracleParameter addDateOutputParam(string ip_name , DateTime ip_value ){
			return m_oracle_command.Parameters.Add(DBParamUtil.getDateOutputParam(ip_name, ip_value));
		}
		public void exec_command(OracleConnection i_oracle_connection) {
			m_oracle_command.Connection = i_oracle_connection;
			m_oracle_command.ExecuteNonQuery();
			m_command_executed = true;
		}
		public decimal getDecimalOutputParaValue(string ip_name){
			System.Diagnostics.Debug.Assert(m_command_executed, "Chua execute thi khong co value dau - csung");
			m_command_executed = false;
			OracleDecimal v_output_result = (OracleDecimal) m_oracle_command.Parameters[ip_name].Value;
			return v_output_result.Value;
		}
		public string getVarcharOutputParaValue(string ip_name)
		{
			System.Diagnostics.Debug.Assert(m_command_executed, "Chua execute thi khong co value dau - csung");
			m_command_executed = false;
			OracleString v_output_result = (OracleString) m_oracle_command.Parameters[ip_name].Value;
			return v_output_result.Value;
		}
		public DateTime getDateTimeOutputParaValue(string ip_name)
		{
			System.Diagnostics.Debug.Assert(m_command_executed, "Chua execute thi khong co value dau - csung");
			m_command_executed = false;
			OracleDate v_output_result = (OracleDate) m_oracle_command.Parameters[ip_name].Value;
			return v_output_result.Value;
		}

		#endregion
	}


}
